/**
 * @file bsp_flash.h
 * @brief FLASH封装驱动
 * @author wangh (wanghuan3037@fiberhome.com)
 * @version 2.0
 * @date 2020-05-09
 * @copyright Copyright (c) 2020  烽火通信
 */
#ifndef __BSP_FLASH_H
#define __BSP_FLASH_H
#include "flash_config.h"

#ifdef STM32F10X
#include "stm32f10x.h"
#elif defined GD32F10X
#include "gd32f10x.h"
#endif


/* page size for chip flash */
#ifndef FLASH_PAGE_SIZE
#ifdef STM32F10X
#if defined(STM32F10X_LD) || defined(STM32F10X_LD_VL) || defined(STM32F10X_MD) || defined(STM32F10X_MD_VL)
#define FLASH_PAGE_SIZE     1024
#else
#define FLASH_PAGE_SIZE     2048
#endif

#elif defined(GD32F10X)
#if defined(GD32F10x_MD)
#define FLASH_PAGE_SIZE     1024
#else
#define FLASH_PAGE_SIZE     2048    /* @NOTE: 双bank的其中bank0的闪存页大小为2KB，bank1的闪存页大小为4KB */
#endif
#endif
#endif

#ifndef FLASH_START_ADDR
#define FLASH_START_ADDR        ((uint32_t)0x08000000)  ///< flash 起始地址
#endif

#ifndef FLASH_SIZE
#define FLASH_SIZE              (1024 * 1024)           ///< flash 容量（单位字节）
#endif

#ifndef FLASH_END_ADDR
#define FLASH_END_ADDR          ((uint32_t)(FLASH_START_ADDR + FLASH_SIZE)) ///< flash 末端地址
#endif


#if 0
/**
 * @brief 芯片内部 Flash 对象结构体
 */
typedef struct Flash_s
{
    uint32_t flash_base_addr;
    uint16_t flash_size;
    uint16_t flash_page_size;

} Flash_t;
#endif



int8_t flash_read( uint32_t addr, void *buf, uint32_t size );

int8_t flash_wite_no_erase( uint32_t addr, void *buf, uint32_t size );
int8_t flash_wite( uint32_t addr, void *buf, uint32_t size );
int8_t flash_copy( uint32_t src_addr, uint32_t dest_addr, uint32_t size );

int8_t flash_erase( uint32_t addr, uint32_t size );
#if defined(STM32F10X_XL) || defined(GD32F10X_XD)
int8_t flash_erase_bank2( void );
#endif

#endif	 // __BSP_FLASH_H 

/*********** (C) COPYRIGHT 2020 FiberHome *****END OF FILE****/
